home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 16 / develop 16 code / CollaboDraw / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-24  |  3.6 KB  |  209 lines  |  [TEXT/MPS ]

  1. /*-------------------------------------------------------------------------------------
  2.  *
  3.  * Simple Sample PowerTalk Application Framework
  4.  *
  5.  * ©1991-1993 Apple Computer
  6.  *
  7.  -------------------------------------------------------------------------------------*/
  8. /*
  9.  * main.c -- main entry point and initialization
  10.  *
  11.  * change history:
  12.  *
  13.  * SJF        08/23/93        1.0f1        update to final headers, fix comments
  14.  * SJF        04/21/93        1.0b2        update to b2
  15.  * SJF        03/01/93        1.0b1        added digital signatures
  16.  * SJF        02/09/93        1.0b1        update to b1
  17.  * SJF        10/13/92        1.0d4        update to a11
  18.  * SJF        09/09/92        1.0d3        update to a9
  19.  * SJF        05/07/92        1.0d2        update to a6
  20.  * SJF        11/06/91        1.0d1        initial coding
  21.  *
  22.  */
  23.  
  24. #ifndef __TRAPS__
  25. #include <Traps.h>
  26. #endif
  27.  
  28. #ifndef __FONTS__
  29. #include <Fonts.h>
  30. #endif
  31.  
  32. #ifndef __MENUS__
  33. #include <Menus.h>
  34. #endif
  35.  
  36. #ifndef __TEXTEDIT__
  37. #include <TextEdit.h>
  38. #endif
  39.  
  40. #ifndef __DIALOGS__
  41. #include <Dialogs.h>
  42. #endif
  43.  
  44. #ifndef __MEMORY__
  45. #include <Memory.h>
  46. #endif
  47.  
  48. #ifndef __PACKAGES__
  49. #include <Packages.h>
  50. #endif
  51.  
  52. #ifndef __TOOLUTILS__
  53. #include <ToolUtils.h>
  54. #endif
  55.  
  56. #ifndef __OSEVENTS__
  57. #include <OSEvents.h>
  58. #endif
  59.  
  60. #include "const.h"
  61. #include "mytypes.h"
  62. #include "mymenus.h"
  63. #include "globals.h"
  64. #include "utils.h"
  65. #include "trapavailable.h"
  66. #include "myevents.h"
  67. #include "mystandardmail.h"
  68. #include "aevt.h"
  69. #include "digisig.h"
  70.  
  71. #include "main.h"
  72.  
  73. /* main entry point */
  74.  
  75. void main(void)
  76. {
  77.     OSErr err;
  78.     
  79.     err = InitToolboxes();            // init the mac toolbox
  80.     if (err!=noErr)
  81.         ExitToShell();
  82.     
  83.     err = InitApplication();        // init our application specific stuff
  84.     if (err!=noErr)
  85.         ExitToShell();
  86.     
  87.     if (gHasStandardMail) {            // init aoce standard mail if available
  88.         err = InitStandardMail();
  89.         if (err!=noErr)
  90.             ExitToShell();
  91.     }
  92.     
  93.     if (gHasDigiSign) {                // init digital signatures if available
  94.         err = InitDigitalSignatures();
  95.         if (err!=noErr)
  96.             ExitToShell();
  97.     }
  98.  
  99.     // lets go!
  100.     
  101.     do {
  102.         MainLoop();
  103.     } while (!ExitProgram());
  104.  
  105.     if (gHasDigiSign)                // clean up after the digital signatures
  106.         ExitDigitalSignatures();
  107.     WritePrefs();                    // write our prefs to disk
  108.     
  109.     ExitToShell();
  110. }
  111.  
  112.  
  113. /* initializes the standard Mac toolbox */
  114.  
  115. OSErr InitToolboxes(void)
  116. {
  117.     OSErr err;
  118.     
  119.     MaxApplZone();
  120.     MoreMasters();
  121.     MoreMasters();
  122.     MoreMasters();
  123.     InitGraf(&qd.thePort);
  124.     InitFonts();
  125.     InitWindows();
  126.     InitMenus();
  127.     TEInit();
  128.     InitDialogs(nil);
  129.     InitCursor();
  130.     FlushEvents(everyEvent,0L);
  131.     
  132.     if (SupportsAEVT()) {
  133.         RegisterMyEvents();
  134.     }
  135.     
  136.     PrOpen();
  137.     err = PrError();
  138.     PrClose();
  139.     
  140.     if (PrError()!=noErr)
  141.         StopAlert(kNoPrinterAlertID,nil);
  142.         
  143.     return err;
  144. }
  145.  
  146.  
  147. /* initializes the application globals/menus/windows/etc... */
  148.  
  149. OSErr InitApplication(void)
  150. {
  151.     CursHandle cursH;
  152.     
  153.     // global variable initialization
  154.     
  155.     gHasWaitNextEvent = TrapAvailable(_WaitNextEvent);
  156.     gHasStandardMail = HasStandardMail();
  157.     gHasDigiSign = HasDigiSign();
  158.         
  159.     gDone = false;
  160.     gInBackground = false;
  161.     gMenusDirty = false;
  162.     gHasCopyWindow = false;
  163.     
  164.     cursH = GetCursor(kPencilCursorID);
  165.     gPencilCursor = **cursH;
  166.     cursH = GetCursor(watchCursor);
  167.     gWatchCursor = **cursH;
  168.  
  169.     gNextWindowToMake = 1;
  170.     
  171.     ReadPrefs();
  172.     InitMyMenus();
  173.     InitMyWindows();
  174.     
  175.     ClearAppUndo();
  176.     
  177.     return noErr;
  178. }
  179.  
  180.  
  181. /* sets up the menu bar */
  182.  
  183. void InitMyMenus(void)
  184. {
  185.     MenuHandle theMenu;
  186.     Handle mbarHandle;
  187.     
  188.     mbarHandle = GetNewMBar(kMenuBar);
  189.     SetMenuBar(mbarHandle);
  190.     
  191.     theMenu = GetMHandle(kAppleMenu);
  192.     AddResMenu(theMenu,'DRVR');            // build apple menu
  193.     
  194.     SetDefaultMenus();
  195.     
  196.     theMenu = GetMHandle(kShapesMenu);
  197.     CheckItem(theMenu,kLineShape,true);
  198.     gCurrentShape = kLineShape;
  199.     
  200.     gMenusDirty = true;
  201. }
  202.  
  203.  
  204. /* displays any initial windows */
  205.  
  206. void InitMyWindows(void)
  207. {
  208. }
  209.